import com.herr.singleton.HungrySingleton;

import java.lang.reflect.Constructor;

public class BreakSingleton {

    public static void main(String[] args) throws Exception {
        Class clazz = Class.forName("com.herr.singleton.HungrySingleton");
        Constructor c = clazz.getDeclaredConstructor(null);

        c.setAccessible(true);

        HungrySingleton s1 = (HungrySingleton)c.newInstance();
        HungrySingleton s2 = (HungrySingleton)c.newInstance();
        //通过反射，得到的两个不同对象
        System.out.println(s1); //com.herr.singleton.HungrySingleton@60e53b93

        System.out.println(s2); //com.herr.singleton.HungrySingleton@5e2de80c

        // 为避免如上漏洞，可在private 构造函数中，添加逻辑判断，多次构造抛出异常
    }

}
